package com.nchu.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.sql.Timestamp;
import java.util.TimeZone;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Repository
public class OrderForm {
    private String data1;
    private String data2;

    private int orderId;
    @Value("已创建")
    private String type;
    private int price;   //价格
    private String title;   //标题
    private String demand;  //需求
    private User billUser;  //投诉者
    private User receiveUser;  //被投诉者

    public void setDeadLine(String data1) {
        String pattern = "yyyy-MM-dd' 'HH:mm:ss";
        SimpleDateFormat inputFormat = new SimpleDateFormat(pattern);
        inputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        try {
            java.util.Date date = inputFormat.parse(data1);
            this.deadLine = new Timestamp(date.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    public void setBillTime(String data2) {
        String pattern = "yyyy-MM-dd' 'HH:mm:ss";
        SimpleDateFormat inputFormat = new SimpleDateFormat(pattern);
        inputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        try {
            java.util.Date date = inputFormat.parse(data2);
            this.billTime = new Timestamp(date.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    private Timestamp billTime;

    @Override
    public String toString() {
        return "OrderForm{" +
                "data1='" + data1 + '\'' +
                ", data2='" + data2 + '\'' +
                ", orderId=" + orderId +
                ", type='" + type + '\'' +
                ", price=" + price +
                ", title='" + title + '\'' +
                ", demand='" + demand + '\'' +
                ", billUser=" + billUser +
                ", receiveUser=" + receiveUser +
                ", billTime=" + billTime +
                ", deadLine=" + deadLine +
                ", deliveryLocation='" + deliveryLocation + '\'' +
                ", remark='" + remark + '\'' +
                ", orderStatus='" + orderStatus + '\'' +
                '}';
    }

    private Timestamp deadLine;   //截至时间
    private String deliveryLocation;   //目的地
    private String remark;
    private int orderStatus;
}
